﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;

namespace Umbrella.Whs.Service.Activities
{

    public sealed class SetWorkflowStatus : SafeCodeActivity
    {
        [RequiredArgument]
        public InArgument<string> Message { get; set; }

        [RequiredArgument]
        public InArgument<bool> HasProgress { get; set; }

        public InArgument<float> Progress { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void ExecuteSafe(CodeActivityContext context)
        {
            var msg = context.GetValue(this.Message);
            var hp = context.GetValue(this.HasProgress);

            // log
            if (_log.IsInfoEnabled)
                _log.Info("Setting status to: " + msg);

            // set status
            if (hp)
            {
                var p = context.GetValue(this.Progress);

                context.SetWorkflowStatus(msg, p);
            }
            else
            {
                context.SetWorkflowStatus(msg);
            }
        }
    }
}
